﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Gui/masterPage.Master" AutoEventWireup="true" CodeBehind="Search.aspx.cs" Inherits="OnlineStore.Gui.Search" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentTitle" runat="server">
    <h1> Tìm Kiếm</h1>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentCenter" runat="server">
    <b>Tiêu chí tìm kiếm</b>
    <div id="content_search" style="background: #F7F7F7; border: 1px solid #DDDDDD; padding: 10px; margin-top: 3px; margin-bottom: 10px;">
      <table>
        <tbody><tr>
          <td>Tìm:</td>
          <td>            
            <%
              if (Request.QueryString.Get("keyword") == null)
              {
           %>
                <input type="text" value="Keywords" id="keyword" onclick="this.value = '';" onkeydown="this.style.color = '000000'" style="color: #999;">
            <%
              }
              else
              {
           %>
            <input type="text" value="<%:Request.QueryString.Get("keyword")%>" id="keyword"  onkeydown="this.style.color = '000000'" style="color: #999;">
           <%
              }
            %>
                <select id="category_id">
                <option value="-1">Tất cả</option>
                <option value="1">loại 1</option>
                <option value="2">loại 2</option>
                <option value="3">loại 3</option>
                </select>
           </td>
        </tr>
        <tr>
          <td colspan="2">            
            <input type="checkbox" <% if(Request.QueryString.Get("Detail")=="1"){ %> checked="checked" <%} %> name="description" id="description">
            Tìm trong chi tiết sản phẩm</td>
        </tr>
		<tr>
          <td colspan="2">            
            <input type="checkbox" <% if(Request.QueryString.Get("Introduce")=="1"){ %> checked="checked" <%} %> name="model" id="model">
              Tìm Trong mô tả sản phẩm</td>
        </tr>
      </tbody></table>
    </div>
    <div class="buttons">
      <table>
        <tbody><tr>
          <td align="right"><a onclick="contentSearch();" class="button"><span>Tìm</span></a></td>
        </tr>
      </tbody></table>
    </div>
    <script type="text/javascript"><!--
        $('#content_search input').keydown(function (e) {
            if (e.keyCode == 13) {
                contentSearch();
            }
        });

        function contentSearch() {
            url = 'Search.aspx?';

            var keyword = $('#keyword').attr('value');
            if (keyword) {
                url += '&keyword=' + encodeURIComponent(keyword);
            }

            var category_id = $('#category_id').attr('value');

            if (category_id) {
                url += '&category_id=' + encodeURIComponent(category_id);
            }

            if ($('#description').attr('checked')) {
                url += '&Detail=1';
            }
            
            if ($('#model').attr('checked')) {
                url += '&Introduce=1';
            }

            location = url;
        }
//--></script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentTop" runat="server">
    <h1>Các sản phẩm tìm thấy </h1>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="MainContent" runat="server">
    <asp:Label ID="numberItem" runat="server" Text="Label" Visible="False"></asp:Label>
    <% 
        if(mainlist==null)
        {
     %>
        <div style="background: #F7F7F7; border: 1px solid #DDDDDD; padding: 10px; margin-top: 3px; margin-bottom: 15px;">
            Không có sản phẩm nào.</div>
    <%
            }
    %>
    <asp:DataList ID="mainlist" runat="server" CellPadding="2" CellSpacing="2" 
        RepeatColumns="4" CssClass="list">
    <ItemTemplate>
                   <a href = "/Gui/ProductDetail.aspx?id=<%#DataBinder.Eval(Container.DataItem, "id")%>">
                    <img src="../img/<%# DataBinder.Eval(Container.DataItem,"Picture")%>" title="<%# DataBinder.Eval(Container.DataItem, "Product_Name")%>" width="120" height="120" alt="<%# DataBinder.Eval(Container.DataItem, "Product_Name")%>"></a><br>
                  <div><img src="../../img/special.png" /><img src="../../img/special.png" /><img src="../../img/special.png" /><img src="../../img/special.png" /><img src="../../img/special.png" /></div>
                 <a href = "/Gui/ProductDetail.aspx?id=<%#DataBinder.Eval(Container.DataItem, "id")%>"><%# DataBinder.Eval(Container.DataItem, "Product_Name")%></a><br>
                 <span style="color: #999; font-size: 11px;"><%# DataBinder.Eval(Container.DataItem, "Type")%></span><br>
                  <span style="color: #900; font-weight: bold;"><%# String.Format("{0:0,0 VNĐ}",DataBinder.Eval(Container.DataItem, "Price"))%> </span> <br>
    </ItemTemplate>
    </asp:DataList>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="ContentButtom" runat="server">
    <div class="pagination">
        
        <%
            int num = OnlineStore.Dal.DalProduct.PageNumber;
            int page = Request.QueryString.Get("page") == null ? 1 : int.Parse(Request.QueryString.Get("page"));
        %>
        <div class="results">Hiển thị từ <%= (page-1)*num %>
         đến
         <%=(page * num < int.Parse(this.numberItem.Text)) ? page * num : int.Parse(this.numberItem.Text)%>
          / tổng 
          <%=int.Parse(this.numberItem.Text)%> 
          sản phẩm (<%=(int)((float)((int.Parse(this.numberItem.Text) / OnlineStore.Dal.DalProduct.PageNumber)) + 0.99)%> Trang)</div>
    </div>
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="Contentlist" runat="server">
    <div class="pagination">
    <div class="links">
        <%
            
            
            int page = Request.QueryString.Get("page") == null ? 1 : int.Parse(Request.QueryString.Get("page"));
            for (int i = 1; i <= (int.Parse(this.numberItem.Text) / OnlineStore.Dal.DalProduct.PageNumber) + 0.99; i++)
                if (i == page)
                {
        %>
                    <b><%=i %></b>
        <%
                }
                else
                {
                    string s = Request.Url.AbsoluteUri;
                    int k = s.IndexOf("&page=");
                    if (k != -1)
                        s = s.Substring(0, k);
                    s += "&page="+ i;
                    
         %>
                <a href="<%:s %>"><%=i%></a>
         <%
                }      
         %>
        </div>
        </div>
</asp:Content>

